﻿// Program.cs
using h1.Data;
using System.Data.SQLite;
using System.Data;

class Program
{
    static void Main()
    {
        DatabaseHelper.InitializeDatabase();

        // 添加学校
        DatabaseHelper.ExecuteNonQuery("INSERT INTO School (Name) VALUES (@name)",
            new SQLiteParameter("@name", "武汉大学"));

        // 添加班级
        DatabaseHelper.ExecuteNonQuery("INSERT INTO Classroom (Name, SchoolId) VALUES (@name, @sid)",
            new SQLiteParameter("@name", "计科1班"),
            new SQLiteParameter("@sid", 1));

        // 添加学生
        DatabaseHelper.ExecuteNonQuery("INSERT INTO Student (Name, ClassroomId) VALUES (@name, @cid)",
            new SQLiteParameter("@name", "李华"),
            new SQLiteParameter("@cid", 1));

        // 查询学生
        DataTable students = DatabaseHelper.ExecuteQuery(
            "SELECT Student.Name, Classroom.Name AS ClassName, School.Name AS SchoolName FROM Student " +
            "JOIN Classroom ON Student.ClassroomId = Classroom.Id " +
            "JOIN School ON Classroom.SchoolId = School.Id");

        Console.WriteLine("学生列表：");
        foreach (DataRow row in students.Rows)
        {
            Console.WriteLine($"学生：{row["Name"]} | 班级：{row["ClassName"]} | 学校：{row["SchoolName"]}");
        }

        // 显示操作日志
        Console.WriteLine("\n操作日志：");
        var logs = DatabaseHelper.GetLogs();
        foreach (DataRow row in logs.Rows)
        {
            Console.WriteLine($"{row["Timestamp"]}: {row["Operation"]}");
        }
    }
}
